package 樱桃网;

import java.util.Scanner;

public class Main {
    static int N = 100010;
    static int[] p = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 1; i <= n; i++) {
                p[i] = i;
            }
            int k = 0;
            while (m-- > 0) {
                int a = in.nextInt();
                int b = in.nextInt();
                if (find(a) != find(b)) {
                    p[find(a)] = p[find(b)];
                    k++;
                }
            }
            System.out.printf("Case #%d: %d\n", cases, k + (n - 1 - k) * 2);
        }
    }

    private static int find(int x) {
        if (p[x] != x) {
            p[x] = find(p[x]);
        }
        return p[x];
    }
}
